import Cookie from 'js-cookie'
export default {
    state: {
        user: '',
        token: ''
    },
    mutations: {
        setUser(state, val) {
            state.user = val
            Cookie.set('user', val)
        },
        getUser(state) {
            state.user = state.user || Cookie.get('user')
        },
        setToken(state, val) {
            state.token = val
            Cookie.set('token', val)
        },
        clearToken(state) {
            state.token = ''
            Cookie.remove('token')
        },
        getToken(state) {
            // 如果state.token不为空，则返回state.token，否则返回Cookie.get('token')
            state.token = state.token || Cookie.get('token')
        }
    }
}